package com.tptj.demo.hg.export.operate.provider;

import com.fanruan.api.log.LogKit;
import com.fr.io.collection.ExportCollection;
import com.fr.stable.EncodeConstants;
import com.fr.stable.web.SessionProvider;
import com.fr.web.core.reserve.DefaultOperate;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;

/**
 * @author 秃破天际
 * @version 10.0
 * Created by 秃破天际 on 2021-04-07
 **/
public class DemoOperate extends DefaultOperate {

    @Override
    public void setContent(HttpServletRequest req, HttpServletResponse res, String fileName, boolean isEmbed ) {
        try{
            res.setContentType("application/json");
            res.setHeader("Content-Disposition", "attachment; filename=\""
                    +URLEncoder.encode(fileName, EncodeConstants.ENCODING_UTF_8)+".json\"");
        }catch (Exception e){
            LogKit.error(e.getMessage(),e);
        }
    }

    @Override
    public ExportCollection newExportCollection(HttpServletRequest req, HttpServletResponse res,
                                                SessionProvider sessionIDInfor, String fileName ){
        ExportCollection collection = ExportCollection.create();
        collection.setExporter( new JsonExporter() );
        collection.setRecordType( JsonRecordType.KEY );
        return collection;
    }
}
